package cn.alm.springmvcrestfulcrud.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
@Schema(description = "返回结果")
public class CR {

    @Schema(description = "返回码")
    private Integer code;
    @Schema(description = "返回信息")
    private String message;
    @Schema(description = "返回数据")
    private Object data;

    public static CR create(Integer code, String message, Object data) {
        CR cr = new CR();
        cr.setCode(code);
        cr.setMessage(message);
        cr.setData(data);
        return cr;
    }

    public static CR success(String msg, Object data) {
        CR cr = new CR();
        cr.setCode(200);
        cr.setMessage(msg);
        cr.setData(data);
        return cr;
    }

    public static CR fail(String msg) {
        CR cr = new CR();
        cr.setCode(500);
        cr.setMessage(msg);
        return cr;
    }

}
